package com.app.library.utils

import android.text.TextUtils
import androidx.annotation.MainThread

object ClickHelper {
    private var lastClickTime: Long = 0
    private var lastButtonId: String? = null

    /**
     * 判断事件出发时间间隔是否超过预定值
     * 如果小于间隔（目前是1000毫秒）则返回true，否则返回false
     */
    @MainThread
    fun isFastDoubleClick(buttonId: String?): Boolean {
        val time = System.currentTimeMillis()
        val timeD = time - lastClickTime
        if (TextUtils.equals(lastButtonId, buttonId) && 0 < timeD && timeD < 500) {
            return true
        }
        lastClickTime = time
        lastButtonId = buttonId
        return false
    }

    fun isFastDoubleClick(): Boolean {
        val time = System.currentTimeMillis()
        val timeD = time - lastClickTime
        if (timeD in 1..500) {
            return true
        }
        lastClickTime = time
        return false
    }
}